package com.lagou.service.impl;

import com.lagou.aop.ETransactional;
import com.lagou.bean.Account;
import com.lagou.dao.AccountDao;
import com.lagou.ioc.EAutowired;
import com.lagou.ioc.EService;
import com.lagou.service.TransferService;

@EService
@ETransactional
public class TransferServiceImpl implements TransferService {
    @EAutowired
    private AccountDao accountDao;

    public TransferServiceImpl() {
    }

    @Override
    public void transfer(String fromCardNo, String toCardNo, int money) throws Exception {
        Account from = accountDao.queryAccountByCardNo(fromCardNo);
        Account to = accountDao.queryAccountByCardNo(toCardNo);
        from.setMoney(from.getMoney()-money);
        to.setMoney(to.getMoney()+money);
        accountDao.updateAccountByCardNo(to);

        //模拟异常
//        int c = 1/0;

        accountDao.updateAccountByCardNo(from);
    }
}
